﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Golf.WebUI.AdminShow.OrderManagement
{
    public partial class OrderModify : Golf.WebUI.App_code.ValidateLogin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int Id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(Id);
                }
            }
        }

        private void ShowInfo(int Id)
        {
            Golf.BLL.Golf_Order bll = new Golf.BLL.Golf_Order();
            Golf.Model.Golf_Order model = bll.GetModel(Id);
            this.lblId.Text = model.Id.ToString();
            this.txtOrderNumber.Text = model.OrderNumber;
            this.txtOrderSumPrice.Text = model.OrderSumPrice.ToString();
            this.txtUserId.Text = model.UserId.ToString();
            this.txtFristName.Text = model.FristName;
            this.txtLastName.Text = model.LastName;
            this.txtProductSumPrice.Text = model.ProductSumPrice.ToString();
            this.txtTransportationPrice.Text = model.TransportationPrice.ToString();
            this.txtMailTypeId.Text = model.MailTypeId.ToString();
            this.chkIsCoupon.Checked = model.IsCoupon;
            this.txtCouponPrice.Text = model.CouponPrice.ToString();
            this.txtIsAddPrice.Text = model.IsAddPrice.ToString();
            this.txtAddPriceState.Text = model.AddPriceState;
            this.txtAddPrice.Text = model.AddPrice.ToString();
            this.txtProductNumberList.Text = model.ProductNumberList;
            this.txtOrderGeneratedTime.Text = model.OrderGeneratedTime.ToString();
            this.txtOrderVerifyTime.Text = model.OrderVerifyTime.ToString();
            this.txtVerifyNameId.Text = model.VerifyNameId.ToString();
            this.txtAddressId.Text = model.AddressId.ToString();
            this.txtUserMessage.Text = model.UserMessage;
            this.txtUserIp.Text = model.UserIp;
            this.txtIsPayment.Text = model.IsPayment.ToString();
            this.txtPaymentTypeId.Text = model.PaymentTypeId.ToString();
            this.txtPaymentBankId.Text = model.PaymentBankId.ToString();
            this.txtPaymentPrice.Text = model.PaymentPrice.ToString();
            this.txtPaymentTime.Text = model.PaymentTime.ToString();
            this.txtPaymentOrderNumber.Text = model.PaymentOrderNumber;
            this.txtRefundTypeId.Text = model.RefundTypeId.ToString();
            this.txtLogisticsStateId.Text = model.LogisticsStateId.ToString();
            this.txtLogisticsnumber.Text = model.Logisticsnumber;
            this.txtPenskeLogistics.Text = model.PenskeLogistics;
            this.txtLogisticsRemarks.Text = model.LogisticsRemarks;
            this.txtOrderStateCodeId.Text = model.OrderStateCodeId.ToString();
            this.txtProductOrderNumber.Text = model.ProductOrderNumber.ToString();
            this.chkIsDeliver.Checked = model.IsDeliver;
            this.txtDeliverTime.Text = model.DeliverTime.ToString();
            this.txtDeliverUnitId.Text = model.DeliverUnitId.ToString();
            this.chkIsPrintDeliver.Checked = model.IsPrintDeliver;
            this.txtAllocateUnitId.Text = model.AllocateUnitId.ToString();
            this.txtAllocateTime.Text = model.AllocateTime.ToString();
            this.txtAdminMessageId.Text = model.AdminMessageId.ToString();
            this.chkIsShow.Checked = model.IsShow;
            this.txtStar.Text = model.Pro_AttrList;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtOrderNumber.Text.Trim().Length == 0)
            {
                strErr += "订单编号不能为空！\\n";
            }
            if (!PageValidate.IsDecimal(txtOrderSumPrice.Text))
            {
                strErr += "订单金额格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtUserId.Text))
            {
                strErr += "会员id Golf_User格式错误！\\n";
            }
            if (this.txtFristName.Text.Trim().Length == 0)
            {
                strErr += "姓	Golf_User表不能为空！\\n";
            }
            if (this.txtLastName.Text.Trim().Length == 0)
            {
                strErr += "名 Golf_User不能为空！\\n";
            }
            if (!PageValidate.IsDecimal(txtProductSumPrice.Text))
            {
                strErr += "产品总价 1个以上的总和格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtTransportationPrice.Text))
            {
                strErr += "运费格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtMailTypeId.Text))
            {
                strErr += "邮寄类型id Golf_Mai格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtCouponPrice.Text))
            {
                strErr += "优惠金额格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtIsAddPrice.Text))
            {
                strErr += "是否加减金额 哦、0否 1加 格式错误！\\n";
            }
            if (this.txtAddPriceState.Text.Trim().Length == 0)
            {
                strErr += "加减金额说明不能为空！\\n";
            }
            if (!PageValidate.IsDecimal(txtAddPrice.Text))
            {
                strErr += "增加为正数格式错误！\\n";
            }
            if (this.txtProductNumberList.Text.Trim().Length == 0)
            {
                strErr += "产品购买多个编号不能为空！\\n";
            }
            if (!PageValidate.IsDateTime(txtOrderGeneratedTime.Text))
            {
                strErr += "盯电脑生成（自动时间）格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtOrderVerifyTime.Text))
            {
                strErr += "订单确认时间格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtVerifyNameId.Text))
            {
                strErr += "确认处理人id Golf_Ad格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtAddressId.Text))
            {
                strErr += "收获地址 Golf_Addre格式错误！\\n";
            }
            if (this.txtUserMessage.Text.Trim().Length == 0)
            {
                strErr += "会员留言不能为空！\\n";
            }
            if (this.txtUserIp.Text.Trim().Length == 0)
            {
                strErr += "会员IP不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtIsPayment.Text))
            {
                strErr += "是否付款 0未 1已付 -1已格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtPaymentTypeId.Text))
            {
                strErr += "付款类型id Golf_Pay格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtPaymentBankId.Text))
            {
                strErr += "付款银行 Golf_bank格式错误！\\n";
            }
            if (!PageValidate.IsDecimal(txtPaymentPrice.Text))
            {
                strErr += "付款金额格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtPaymentTime.Text))
            {
                strErr += "付款时间格式错误！\\n";
            }
            if (this.txtPaymentOrderNumber.Text.Trim().Length == 0)
            {
                strErr += "付款第三方订单号不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtRefundTypeId.Text))
            {
                strErr += "退款记录id Golf_Log格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtLogisticsStateId.Text))
            {
                strErr += "物流状态id Golf_Log格式错误！\\n";
            }
            if (this.txtLogisticsnumber.Text.Trim().Length == 0)
            {
                strErr += "物流订单号不能为空！\\n";
            }
            if (this.txtPenskeLogistics.Text.Trim().Length == 0)
            {
                strErr += "物流公司名称不能为空！\\n";
            }
            if (this.txtLogisticsRemarks.Text.Trim().Length == 0)
            {
                strErr += "物流备注说明不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtOrderStateCodeId.Text))
            {
                strErr += "物流状态id	Golf_Log格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtProductOrderNumber.Text))
            {
                strErr += "订单总件数格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtDeliverTime.Text))
            {
                strErr += "发货时间格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtDeliverUnitId.Text))
            {
                strErr += "发货处理人id	Golf_Ad格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtAllocateUnitId.Text))
            {
                strErr += "配货处理人id	Golf_Ad格式错误！\\n";
            }
            if (!PageValidate.IsDateTime(txtAllocateTime.Text))
            {
                strErr += "配货时间格式错误！\\n";
            }
            if (!PageValidate.IsNumber(txtAdminMessageId.Text))
            {
                strErr += "后台处理人留言id	Golf_格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int Id = int.Parse(this.lblId.Text);
            string OrderNumber = this.txtOrderNumber.Text;
            decimal OrderSumPrice = decimal.Parse(this.txtOrderSumPrice.Text);
            int UserId = int.Parse(this.txtUserId.Text);
            string FristName = this.txtFristName.Text;
            string LastName = this.txtLastName.Text;
            decimal ProductSumPrice = decimal.Parse(this.txtProductSumPrice.Text);
            decimal TransportationPrice = decimal.Parse(this.txtTransportationPrice.Text);
            int MailTypeId = int.Parse(this.txtMailTypeId.Text);
            bool IsCoupon = this.chkIsCoupon.Checked;
            decimal CouponPrice = decimal.Parse(this.txtCouponPrice.Text);
            int IsAddPrice = int.Parse(this.txtIsAddPrice.Text);
            string AddPriceState = this.txtAddPriceState.Text;
            decimal AddPrice = decimal.Parse(this.txtAddPrice.Text);
            string ProductNumberList = this.txtProductNumberList.Text;
            DateTime OrderGeneratedTime = DateTime.Parse(this.txtOrderGeneratedTime.Text);
            DateTime OrderVerifyTime = DateTime.Parse(this.txtOrderVerifyTime.Text);
            int VerifyNameId = int.Parse(this.txtVerifyNameId.Text);
            int AddressId = int.Parse(this.txtAddressId.Text);
            string UserMessage = this.txtUserMessage.Text;
            string UserIp = this.txtUserIp.Text;
            int IsPayment = int.Parse(this.txtIsPayment.Text);
            int PaymentTypeId = int.Parse(this.txtPaymentTypeId.Text);
            int PaymentBankId = int.Parse(this.txtPaymentBankId.Text);
            decimal PaymentPrice = decimal.Parse(this.txtPaymentPrice.Text);
            DateTime PaymentTime = DateTime.Parse(this.txtPaymentTime.Text);
            string PaymentOrderNumber = this.txtPaymentOrderNumber.Text;
            int RefundTypeId = int.Parse(this.txtRefundTypeId.Text);
            int LogisticsStateId = int.Parse(this.txtLogisticsStateId.Text);
            string Logisticsnumber = this.txtLogisticsnumber.Text;
            string PenskeLogistics = this.txtPenskeLogistics.Text;
            string LogisticsRemarks = this.txtLogisticsRemarks.Text;
            int OrderStateCodeId = int.Parse(this.txtOrderStateCodeId.Text);
            int ProductOrderNumber = int.Parse(this.txtProductOrderNumber.Text);
            bool IsDeliver = this.chkIsDeliver.Checked;
            DateTime DeliverTime = DateTime.Parse(this.txtDeliverTime.Text);
            int DeliverUnitId = int.Parse(this.txtDeliverUnitId.Text);
            bool IsPrintDeliver = this.chkIsPrintDeliver.Checked;
            int AllocateUnitId = int.Parse(this.txtAllocateUnitId.Text);
            DateTime AllocateTime = DateTime.Parse(this.txtAllocateTime.Text);
            int AdminMessageId = int.Parse(this.txtAdminMessageId.Text);
            bool IsShow = this.chkIsShow.Checked;


            Golf.Model.Golf_Order model = new Golf.Model.Golf_Order();
            model.Id = Id;
            model.OrderNumber = OrderNumber;
            model.OrderSumPrice = OrderSumPrice;
            model.UserId = UserId;
            model.FristName = FristName;
            model.LastName = LastName;
            model.ProductSumPrice = ProductSumPrice;
            model.TransportationPrice = TransportationPrice;
            model.MailTypeId = MailTypeId;
            model.IsCoupon = IsCoupon;
            model.CouponPrice = CouponPrice;
            model.IsAddPrice = IsAddPrice;
            model.AddPriceState = AddPriceState;
            model.AddPrice = AddPrice;
            model.ProductNumberList = ProductNumberList;
            model.OrderGeneratedTime = OrderGeneratedTime;
            model.OrderVerifyTime = OrderVerifyTime;
            model.VerifyNameId = VerifyNameId;
            model.AddressId = AddressId;
            model.UserMessage = UserMessage;
            model.UserIp = UserIp;
            model.IsPayment = IsPayment;
            model.PaymentTypeId = PaymentTypeId;
            model.PaymentBankId = PaymentBankId;
            model.PaymentPrice = PaymentPrice;
            model.PaymentTime = PaymentTime;
            model.PaymentOrderNumber = PaymentOrderNumber;
            model.RefundTypeId = RefundTypeId;
            model.LogisticsStateId = LogisticsStateId;
            model.Logisticsnumber = Logisticsnumber;
            model.PenskeLogistics = PenskeLogistics;
            model.LogisticsRemarks = LogisticsRemarks;
            model.OrderStateCodeId = OrderStateCodeId;
            model.ProductOrderNumber = ProductOrderNumber;
            model.IsDeliver = IsDeliver;
            model.DeliverTime = DeliverTime;
            model.DeliverUnitId = DeliverUnitId;
            model.IsPrintDeliver = IsPrintDeliver;
            model.AllocateUnitId = AllocateUnitId;
            model.AllocateTime = AllocateTime;
            model.AdminMessageId = AdminMessageId;
            model.IsShow = IsShow;

            Golf.BLL.Golf_Order bll = new Golf.BLL.Golf_Order();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}